//
//  ContentView.swift
//  todoList
//
//  Created by Aoyun on 02/01/2025.
//

import SwiftUI

struct ContentView: View {
    @Environment(ListViewModel.self) private var listViewModel
    var body: some View {
        ZStack {
            if listViewModel.todoList.isEmpty {
                emptyView()
                    .transition(AnyTransition.opacity.animation(.easeInOut))
            } else {
                List {
                    ForEach(listViewModel.todoList) { item in
                        todoView(item: item)
                    }
                    .onDelete(perform: listViewModel.deleteList)
                    .onMove(perform: listViewModel.moveList)
                }
            }
        }
        .listStyle(.plain)
        .navigationTitle("ToDoList ✍️")
        .toolbar {
            ToolbarItem(placement: .topBarLeading, content: {
                EditButton()
            })
            ToolbarItem(placement: .topBarTrailing, content: {
                NavigationLink("Add", destination: addTodoView())
            })
        }
    }
}

#Preview {
    NavigationStack {
        ContentView().environment(ListViewModel())
    }
}
